﻿using Controller.Enum;
using Controller.Model;
using Leeder.Logger;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerManageServer.ActionModel.AioiNW
{
    /// <summary>
    /// NW2991无线标签
    /// </summary>
    class AioiNWActionModelNW2991 : AioiNWActionModelAbstract
    {

        /// <summary>
        /// 模式组合
        /// </summary>
        /// <returns></returns>
        public override byte[] ModeArray()
        {
            List<byte> result = new List<byte>();
            result.Add((byte)((byte)LightMode % 2));// 闪烁为0，亮灯为1
            byte temp = GetLightColor(LightMode);// 亮灯模式
            if (IsOpenBuzzers) temp |= 8;// 是否闪烁
            result.Add(temp);

            // 参考文档,一个字节转16进制后只取一位
            string res = "", tempStr;
            for (int i = 0; i < result.Count; i++) {
                tempStr = String.Format("{0:x1}", result[i]);
                if(tempStr.Length > 1)
                    tempStr = tempStr.Substring(1);
                res += tempStr;
            }

            return DefaultEncoding.GetBytes(res);
        }

        public override void ToActionModel(ActionPacketModel iModel)
        {
            IsOpenBuzzers = iModel.ControlModel.OpenBuzzer != DeviceBuzzerStatuEnum.OFF;
            LightMode = iModel.ControlModel.LightModel;
        }
    }
}
